package crack_sda2;

import java.io.IOException;

import math2.MathUtilities;
import fem2.Element;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.Model;
import fem2.element.crack_sda2.SKONConstantJumpCSTElement;
import fem2.material.FluencyCriteria;
import fem2.material.cohesive_law2.CohesiveLaw;
import fem2.material.cohesive_law2.SanchoCohesiveLaw;
import fem2.pre_and_post.GidMeshGenerator;

public class LshapeTriMeshYijianSKONConstantJumpCSTElementAndSanchoCohesiveLaw extends
		AbstractLshapeUsingSDAElementDemo {

	public LshapeTriMeshYijianSKONConstantJumpCSTElementAndSanchoCohesiveLaw() {
		meshFileName = "mesh1-skon-sancho.msh";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(2);
		return mesh;
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		final double ft = 2.7;
		final double Gf = 0.065;

		FluencyCriteria softeningRule = new FluencyCriteria() {

			@Override
			public double computeFluencyValue(double v) {
				return ft * Math.exp(-v * ft / Gf);
			}

			@Override
			public double computeFluencyDerivative(double v) {
				double f = computeFluencyValue(v);
				return -(ft / Gf) * f;
			}
		};

		return new SanchoCohesiveLaw(Gf, ft, softeningRule);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		Element e = new SKONConstantJumpCSTElement(mp, mm, cl);
		// e.setEchoLevel(EchoLevelType.OUTPUT);
		return e;
	}

	public static void main(String[] args) throws IOException {

		AbstractLshapeUsingSDAElementDemo sample = new LshapeTriMeshYijianSKONConstantJumpCSTElementAndSanchoCohesiveLaw();

		// double[] lambda = MathUtilities.createLambdaArray(7.5, 0.1, 7.8);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 10);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 15);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 20);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 25);
		// double[] lambda = MyLinAlg.createLambdaArray(7.5, 0.1, 7.6, 0.05,
		// 30);
		// double[] lambda = MathUtilities.createLambdaArray(7.5, 0.1, 7.6,
		// 0.05, 26, 0.01, 30); //notable result
		// double[] lambda = MathUtilities.createLambdaArray(7.5, 0.1, 7.6,
		// 0.05, 26, 0.01, 30, 0.005,
		// 35);// notable result
		double[] lambda = MathUtilities.createLambdaArray(7.5, 0.1, 7.6, 0.05, 26, 0.01, 30, 0.005,
				40);// not converge

		sample.run(lambda);

	}
}
